
$(document).ready(function() {
    
	var ue = UE.getEditor('editor');
	
	var categoryId = 4001;	//随意发挥
	
	/* 发贴操作 */
	$(".fa-tie-bt").click(function() {
		var title = $.trim($(".in-tie-title").val());
		var content = UE.getEditor('editor').getContent();
		if(title.length == 0) {
			Utils.msgDialog("请输入贴子标题！");
			return;
		} else if(Utils.countLength(title) > 60) {
			Utils.msgDialog("贴子标题过长（60个字符以内）！");
			return;
		}
		
		var param = {
			fatherId: 0,
			categoryId: categoryId,
			title: title,
			content: content,
		};
		AQ.callAQJSON("createEntry.do", param, function(result) {
			Utils.msgDialog("发贴成功！");
			var id = result.info;
			location.replace("forum-read.html?id="+ id +"&type=1");
		}, function(err, code){
			Utils.msgDialog(err + "["+ code +"]");
		});
	});
	
	$(".in-tie-title").keyup(function() {
		var title = $.trim($(".in-tie-title").val());
		if(Utils.countLength(title) > 60) {
			var temp = "";
			for(var i = 0; i< title.length; i++) {				
				if(Utils.countLength(temp + title.substr(i, 1)) > 60) {
					$(".in-tie-title").val(temp);
					break;
				} else {
					temp += title.substr(i, 1);
				}
			}
		}
	});
	
	/* 选择标签 */
	$(".new-cat-tag").each(function(index, element) {
        $(element).click(function() {
			var arr = $(".new-cat-tag");
			for(var i=0; i<arr.length; i++) {
				if(i == index) {
					$(element).css("background", "#BACD00");
					categoryId = $(element).val();
				} else {
					$(arr[i]).css("background", "#54B0F5");
				}
			}
        });
    });
	
});